home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / Acme Filters 2.3.2 folder.sit / Acme Filters 2.3.2 folder / Acme Filters 2.3.2 / Acme Filters オ / Sources / Tab2Space.c < prev    next >
Text File  |  1996-03-02  |  2KB  |  82 lines

  1. /************ I N C L U D E   F I L E S *******************************************************/
  2.  
  3. #include <stdio.h>
  4.  
  5. #include "Acme Filters.h"
  6. #include "Tab2Space.h"
  7.  
  8.  
  9.  
  10. /**********************************************************************************************
  11.  * Function Name:  Tab2Space
  12.  *
  13.  * Description:    Convert tabs to equivalent spaces.
  14.  *
  15.  * Parameters:     iFile - file spec of a file.
  16.  *
  17.  * Return Value:   None.
  18.  **********************************************************************************************/
  19. void    Tab2Space( FSSpec *iFile )
  20. {
  21.     FILE    *iFp, *oFp;
  22.     char    iBuf[kBufSize];
  23.     char    *c;
  24.     FSSpec    oFile;
  25.     FInfo    iInfo, oInfo;
  26.     
  27.     short    pad, col = 0;
  28.     
  29.     // create and open the output file
  30.     FSMakeFSSpec( iFile->vRefNum, iFile->parID, iFile->name, &oFile );
  31.     pstrcpy( oFile.name, kTempFileName );    // use a temporary name
  32.     oFp = FSpfopen( &oFile, "wb" );
  33.     
  34.     // set the output file's type and creator
  35.     FSpGetFInfo( iFile, &iInfo );
  36.     FSpGetFInfo( &oFile, &oInfo );
  37.     oInfo.fdType = iInfo.fdType;
  38.     oInfo.fdCreator = iInfo.fdCreator;
  39.     FSpSetFInfo( &oFile, &oInfo );
  40.     
  41.     // filter the input file
  42.     if ( iFp = FSpfopen( iFile, "rb" ) )
  43.     {
  44.         while ( fgets( iBuf, kBufSize-1, iFp ) != nil )
  45.         {
  46.             gCancelReq |= Cancel();
  47.             ScrollIcon();
  48.             c = iBuf;
  49.             while ( *c )
  50.             {
  51.                 if ( *c == kTab )    // replace tabs with spaces
  52.                 {
  53.                     pad = kTabSize - ( col % kTabSize );
  54.                     while ( pad-- )
  55.                     {
  56.                         fputc( kSpace, oFp );
  57.                         col++;
  58.                     }
  59.                 }
  60.                 else                // let everything else go unchanged
  61.                 {
  62.                     fputc( *c, oFp );
  63.                     col++;
  64.                 }
  65.                 
  66.                 if ( *c == kCR ) col = 0;
  67.                 c++;
  68.             }
  69.         }
  70.     }
  71.     
  72.     // close the files
  73.     if ( iFp ) fclose( iFp );
  74.     if ( oFp ) fclose( oFp );
  75.     
  76.     // swap the contents of the two files and delete the copy
  77.     FSpExchangeFiles( &oFile, iFile );
  78.     FSpDelete( &oFile );
  79.     
  80.     TickleParentDir( &oFile );
  81. }
  82.